import axios from "axios";
import { Toast } from "vant";
import "vant/es/toast/style";

const reque = axios.create({
  baseURL: "https://www.lexuemiao.com/api/app",
  // baseURL: "http://tian.tianguixing.com:4001/api/private/v1",
  timeout: 5000,
});
const whitList = ["/login", "/LiveDetalis"];
reque.interceptors.request.use(
  (config) => {
    // 拼接token
    let tokens = JSON.parse(localStorage.getItem("token")) || [];
    const { remember_token } = tokens;
    config.headers.zywxtoken = "zywx" + remember_token;

    // 提示
    Toast.loading({
      message: "加载中...",
      forbidClick: true,
      duration: 0,
    });
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

reque.interceptors.response.use(
  (res) => {
    Toast.clear();
    return res.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export default reque;
